package com.guanyong.www.controllers.api;

import com.guanyong.model.*;
import com.guanyong.services.KeybaseDetailsService;
import com.guanyong.services.KeybaseService;
import com.guanyong.services.MaoyanService;
import com.guanyong.utils.Comm.DateExt;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * Created by mxk on 2017/7/16.
 */
@RestController
@RequestMapping("/api/details/")
public class DetailsApi {

    @Autowired
    KeybaseDetailsService keybaseDetailsService;

    @Autowired
    MaoyanService maoyanService;
    @RequestMapping(value = "getzhishu", method = RequestMethod.GET)
    public ResultObject<List<KeyJavaZhishuModel>> getzhishu(@RequestParam int id){
        ResultObject<List<KeyJavaZhishuModel>> result = new ResultObject<List<KeyJavaZhishuModel>>();
        result.setResult(keybaseDetailsService.getZhishuById(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }


    @RequestMapping(value = "getzhishu30", method = RequestMethod.GET)
    public ResultObject<Map<String,Object>> getzhishu30(@RequestParam int id){
        ResultObject<Map<String,Object>> result = new ResultObject<Map<String,Object>>();
        result.setResult(keybaseDetailsService.getZhishu30ById(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }
    @RequestMapping(value = "getweibozhishu", method = RequestMethod.GET)
    public ResultObject<List<KeyWeiboZhishuCountModel>> getweibozhishu(@RequestParam int id){
        ResultObject<List<KeyWeiboZhishuCountModel>> result = new ResultObject<List<KeyWeiboZhishuCountModel>>();
        result.setResult(keybaseDetailsService.getKeyWeiboZhishuById(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }

    @RequestMapping(value = "getpingfen", method = RequestMethod.GET)
    public ResultObject<List<KeyPingfenModel>> getpingfen(@RequestParam int id){
        ResultObject<List<KeyPingfenModel>> result = new ResultObject<List<KeyPingfenModel>>();
        result.setResult(keybaseDetailsService.getKeyPingfenByIdDay(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }


    @RequestMapping(value = "getbozhutop5", method = RequestMethod.GET)
    public ResultObject<List<KeyBozhuModel>> getbozhutop5(@RequestParam int id){
        ResultObject<List<KeyBozhuModel>> result = new ResultObject<List<KeyBozhuModel>>();
        result.setResult(keybaseDetailsService.getKeyBozhuTop5(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }

    @RequestMapping(value = "getKeyHuatiTop3", method = RequestMethod.GET)
    public ResultObject<List<KeyHuatiModel>> getKeyHuatiTop3(@RequestParam int id){
        ResultObject<List<KeyHuatiModel>> result = new ResultObject<List<KeyHuatiModel>>();
        result.setResult(keybaseDetailsService.getKeyHuatiTop3(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }


    @RequestMapping(value = "getKeyWeiboTop5", method = RequestMethod.GET)
    public ResultObject<List<KeyWeiboModel>> getKeyWeiboTop5(@RequestParam int id){
        ResultObject<List<KeyWeiboModel>> result = new ResultObject<List<KeyWeiboModel>>();
        result.setResult(keybaseDetailsService.getKeyWeiboTop5(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }
    @RequestMapping(value = "getKeyFilm", method = RequestMethod.GET)
    public ResultObject<List<KeyFilmModel>> getKeyFilm(@RequestParam int id){
        ResultObject<List<KeyFilmModel>> result = new ResultObject<List<KeyFilmModel>>();
        result.setResult(keybaseDetailsService.getKeyFilm(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }


    @RequestMapping(value = "getPiaofangList", method = RequestMethod.GET)
    public ResultObject<List<KeyPiaofangDateModel>> getPiaofangList(@RequestParam int id){
        ResultObject<List<KeyPiaofangDateModel>> result = new ResultObject<List<KeyPiaofangDateModel>>();
        List<KeyPiaofangModel> oldList =keybaseDetailsService.getLodPiaofangByIdList(id);
        List<KeyPiaofangDateModel> lsit = new ArrayList<KeyPiaofangDateModel>();
        for (KeyPiaofangModel keyPiaofangModel:oldList){
            KeyPiaofangDateModel keyPiaofangDateModel = new KeyPiaofangDateModel();
            keyPiaofangDateModel.setCurDate(keyPiaofangModel.getCurDate());
            keyPiaofangDateModel.setNum(keyPiaofangModel.getPiaofang());
            lsit.add(keyPiaofangDateModel);
        }
        KeyPiaofangModel keyPiaofangModel =keybaseDetailsService.getNowPiaofangById(id);
        if (keyPiaofangModel!=null){
            KeyPiaofangDateModel keyPiaofangDateModel = new KeyPiaofangDateModel();
            keyPiaofangDateModel.setCurDate(keyPiaofangModel.getCurDate());
            keyPiaofangDateModel.setNum(keyPiaofangModel.getPiaofang());
            lsit.add(keyPiaofangDateModel);
        }
        Collections.reverse(lsit);
        result.setResult(lsit);
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }


    @RequestMapping(value = "getPiaofangNow", method = RequestMethod.GET)
    public ResultObject<Map<String,Long>> getPiaofangNow(@RequestParam int id){
        ResultObject<Map<String,Long>> result = new ResultObject<Map<String,Long>>();
        List<KeyPiaofangModel> oldList =keybaseDetailsService.getPiaofangByIdList(id);
        Map<String,Long> map = new HashMap<String, Long>();
        int sum=0;
        for (KeyPiaofangModel keyPiaofangModel:oldList){
            sum+=keyPiaofangModel.getPiaofang();
        }
        KeyPiaofangModel keyPiaofangModel =keybaseDetailsService.getNowPiaofangById(id);
        if (keyPiaofangModel==null){
            map.put("now",0l);
        }else {
            map.put("now",keyPiaofangModel.getPiaofang());
        }
        map.put("sum",sum+map.get("now"));
        result.setResult(map);
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }


    @RequestMapping(value = "getmovieinfo", method = RequestMethod.GET)
    public ResultObject<MaoyanMovieModel> getmovieinfo(@RequestParam int movieid){
        ResultObject<MaoyanMovieModel> result = new ResultObject<MaoyanMovieModel>();
        result.setResult(maoyanService.GetMaoyanByMovieMovieId(movieid));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }


    @RequestMapping(value = "getmoviecompany", method = RequestMethod.GET)
    public ResultObject<List<MaoyanCompanyModel>> getmoviecompany(@RequestParam int movieid){
        ResultObject<List<MaoyanCompanyModel>> result = new ResultObject<List<MaoyanCompanyModel>>();
        result.setResult(maoyanService.GetMaoyanCompanyList(movieid));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }


    @RequestMapping(value = "getmovieyanyuan", method = RequestMethod.GET)
    public ResultObject<List<MaoyanCelebrityModel>> getmovieyanyuan(@RequestParam int movieid){
        ResultObject<List<MaoyanCelebrityModel>> result = new ResultObject<List<MaoyanCelebrityModel>>();
        result.setResult(maoyanService.GetMaoyanCelebrityList(movieid));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }

    @RequestMapping(value = "getmoviehuaxiang", method = RequestMethod.GET)
    public ResultObject<MaoYanHuaXiangModel> getmoviehuaxiang(@RequestParam int baseid){
        ResultObject<MaoYanHuaXiangModel> result = new ResultObject<MaoYanHuaXiangModel>();
        String date= DateExt.GetNowDateStr();
        result.setResult(maoyanService.GetMaoYanhuaXiangByBaseId(baseid,date));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }

    @RequestMapping(value = "getPlayCount", method = RequestMethod.GET)
    public ResultObject<List<KeyPlayCountModel>> getPlayCount(@RequestParam int id){
        ResultObject<List<KeyPlayCountModel>> result = new ResultObject<List<KeyPlayCountModel>>();
        result.setResult(keybaseDetailsService.getPlayCountById(id));
        result.setErrorMsg(ResultCode.OperateOk);
        return result;
    }
}
